<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\file\FileInput;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use kartik\markdown\MarkdownEditor;
use kartik\markdown\Markdown;

/* @var $this yii\web\View */
/* @var $model common\models\Goods */
/* @var $form yii\widgets\ActiveForm */
?>
<style>
    　　.demo img {
        　　　　width: 736px;
        　　　　height: 490px;
        　　　　background: url(images/loading.gif) 50% no-repeat;}
</style>
<style>
    .GallImages { width: 100%; margin: 0 auto; font-family: arial,SimSun; font-size: 0;border: 2px solid salmon}
    .GallImages .item { display: inline-block; width: 230px;  margin: 0 20px 20px 0; background-color: #ccc;}
    .GallImages span { display: block; height: 100px; line-height: 100px; font-size: 2rem; text-align: center; color: #fff;}
    .DescImages { width: 100%;  margin: 0 auto; font-family: arial,SimSun; font-size: 0;border: 2px solid salmon}
    .DescImages .item { display: inline-block; width: 230px;  margin: 0 20px 20px 0; background-color: #ccc;}
    .DescImages span { display: block; height: 100px; line-height: 100px; font-size: 2rem; text-align: center; color: #fff;}
</style>
<div class="goods-form">
    <input type="hidden" id = 'FormPageType' value="<?=$FormPage?>" >
    <?php $form = ActiveForm::begin(); ?>
    <div class="FormPage01" style="display: none">
        <input type="hidden" name="_csrf" id='csrf' value="<?= Yii::$app->request->csrfToken ?>">
        <?= $form->field($model, 'goods_id')->hiddenInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'goods_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'shop_price')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'market_price')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'weight')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'is_new')->radioList(['否', '是']) ?>

    <?= $form->field($model, 'is_hot')->radioList(['否', '是']) ?>

    <?= $form->field($model, 'is_good')->radioList(['否', '是']) ?>

    <?= $form->field($model, 'is_promote')->radioList(['否', '是']) ?>

    <?= $form->field($model, 'is_delete')->radioList(['否', '是']) ?>

    <?= $form->field($model, 'is_single')->radioList(['否', '是']) ?>

        <?= $form->field($model, 'is_gift')->radioList(['否', '是']) ?>

    </div>

    <div class="FormPage02" style="display: none">
        <?= $form->field($model, 'cate_id')->textInput(['maxlength' => true]) ?>
        <?= $form->field($model, 'attr_cat_id')->dropDownList(\yii\helpers\ArrayHelper::map(
            \backend\modules\goods\models\Attrcat::find()->select(['attr_cat_id','attr_cat_name'])->asArray()->all(),
            'attr_cat_id',
            'attr_cat_name'
        ),
            [
                'prompt'=>'请选择',
            ]
        );?>

        <div id="attribute-attrValue">

        </div>
    </div>
    <div class="FormPage03" style="display: none">
        <?php
            echo MarkdownEditor::widget([
                'model' => $model,
                'attribute' => 'goods_desc',
            ]);
        ?>

    </div>
    <div class="FormPage04" style="display: none">

        <?php
        $initialPreview =  array();
        $initialPreviewConfig = array();
        foreach($GoodsGallImages as $k=>$v) {
            $initialPreview[] = "<img width='100%' height='100%' src='" .  '../' . $v['goods_gall_image'] . "' class='file-preview-image'>";
            $initialPreviewConfig[] = [
                'caption' => $v['goods_gall_image'],
                'url' => Url::to(['/goods/goods/deleteimage', 'id' => $v['goods_gall_images_id']]),
            ];
        }
        ?>
        <?=$form->field($model, 'gallImages[]')->label(Yii::t('catalog','Image(请先上传图片)'))->widget(FileInput::classname(), [
            'language' => 'zh',
            'options' => [ 'accept' => 'image/*', 'multiple'=>true],
            'pluginOptions' => [
                'initialPreview'=>$initialPreview,
                'initialPreviewConfig'=>$initialPreviewConfig,
                'overwriteInitial'=>false,
                'showCaption'=>true,
                'showCancel'=>true,
                'showBrowse'=>true,
                'uploadUrl' => Url::to(['/goods/goods/gallupload']),
                'uploadExtraData' => [
                    'goods_id' => $model->goods_id,
                    'goods_name' => $model->goods_name,
                    'position' => 5//TODO:  js
                ],
                'dropZoneEnabled'=>true,
                'maxFileCount' => 10,
                'allowedFileExtensions'=>['jpg','gif','png']
            ]
        ]);?>

        <div style="text-align: center;"><img width="20%;" src="../web/images/useFB/lookdown.png" /></div>
        <a href="<?=Url::to(['/goods/goods/updatepage','id' => $model->goods_id,'whiceForm'=>'FormPage04'])?>" style="width: 100%;height: 80px;font-size: 25px;  line-height:55px; " class="btn btn-info">上传成功后请点击此处（添加图片至拖动排序区并系统自动整理排序）</a>
        <div style="width: 100%;height: 80px;font-size: 25px;  line-height:55px;text-align: center; border: 2px solid salmon ;margin-top:5px" >拖动图片排序</div>
        <div class="GallImages">
            <?php foreach($GoodsGallImages as $k=>$v) {
                $sort = $k+1;
                echo  '<div id="'.$v['goods_gall_images_id'].'" class="item item'.$sort.'">'.
                    "<img width='100%'  src='" .  '../' . $v['goods_gall_image'] . "' class='file-preview-image'>".
                    '</div>';
            }?>
        </div>
        <script>
            $(function(){
                $('.GallImages').dad();
            });
        </script>

    </div>

    <div class="FormPage05" style="display: none">
        <input name="pooai_pages_id" type="hidden" id="pooai_pages_id" value="" />

        <?php
        $initialPreview =  array();
        $initialPreviewConfig = array();
        foreach($GoodsDescImages as $k=>$v) {
            $initialPreview[] = "<img width='100%' height='100%' data-echo='images/big-1.jpg' src='" .  '../' . $v['goods_desc_image'] . "' class='lazy file-preview-image'>";
            $initialPreviewConfig[] = [
                'caption' => $v['goods_desc_image'],
                'url' => Url::to(['/goods/goods/deleteimage', 'id' => $v['goods_desc_images_id'],'imagesType'=>'DescImages']),
            ];
        }
        ?>
        <?=$form->field($model, 'descImages[]')->label(Yii::t('catalog','Image(请先上传图片)'))->widget(FileInput::classname(), [
            'language' => 'zh',
            'options' => [ 'accept' => 'image/*', 'multiple'=>true],
            'pluginOptions' => [
                'initialPreview'=>$initialPreview,
                'initialPreviewConfig'=>$initialPreviewConfig,
                'overwriteInitial'=>false,
                'uploadUrl' => Url::to(['/goods/goods/descupload']),
                'uploadExtraData' => [
                    'goods_id' => $model->goods_id,
                    'goods_name' => $model->goods_name,
                    'position' => 5//TODO:  js
                ],
                'dropZoneEnabled'=>true,
                'maxFileCount' => 10,
                'allowedFileExtensions'=>['jpg','gif','png']
            ]
        ]);?>
<!--        <div style="text-align: center;"><img width="20%;" src="../web/images/useFB/lookdown.png" /></div>-->
<!--        <div style="width: 100%;height: 80px;font-size: 25px;  line-height:55px;text-align: center; border: 2px solid salmon ;margin-top:5px" >拖动图片排序</div>-->
<!--        <div class="DescImages">-->
<!--<!--            //foreach($GoodsDescImages as $k=>$v) {-->
<!--//                $sort = $k+1;-->
<!--//                echo  '<div id="'.$v['goods_desc_images_id'].'" class="item item'.$sort.'">'.-->
<!--//                    "<img width='100%'  src='" .  '../' . $v['goods_desc_image'] . "' class='file-preview-image'>".-->
<!--//                    '</div>';-->
<!--//            -->
<!--        </div>-->
<!--        <script>-->
<!--            $(function(){-->
<!--                $('.DescImages').dad();-->
<!--            });-->
<!--        </script>-->

        <div style="text-align: center;"><img width="20%;" src="../web/images/useFB/lookdown.png" /></div>
        <?php if($model->is_gift==1) {?>
            <a href="<?=Url::to(['/goods/goods/sortdesc','id' => $model->goods_id])?>" style="width: 100%;height: 80px;font-size: 25px;  line-height:55px; " class="btn btn-info">点击去排序图片详情</a>
        <?php } else { ?>
            <a href="<?=Url::to(['/goods/goods/updatepage','id' => $model->goods_id,'whiceForm'=>'FormPage05'])?>" style="width: 100%;height: 80px;font-size: 25px;  line-height:55px; " class="btn btn-info">点击去排序图片详情</a>
            <div style="width: 100%;height: 80px;font-size: 25px;  line-height:55px;text-align: center; border: 2px solid salmon ;margin-top:5px" >拖动图片排序</div>
            <div class="DescImages">
                <?php foreach($GoodsDescImages as $k=>$v) {
                    $sort = $k+1;
                    echo  '<div id="'.$v['goods_desc_images_id'].'" class="item item'.$sort.'">'.
                        "<img width='100%'  src='" .  '../' . $v['goods_desc_image'] . "' class='file-preview-image'>".
                        '</div>';
                }?>
            </div>
        <?php } ?>
                <script>
                    $(function(){
                        $('.DescImages').dad();
                    });
                </script>
    </div>
    <div class="form-group" id="form-group-submit-btn">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', '确认新建') : Yii::t('app', '确认修改'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>
    <?php $form = ActiveForm::end(); ?>
</div>

